import java.util.Scanner;

/**
 * @Title: 合并集合
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/5 21:08
 * @description: 经典的并查集问题
 */
public class 合并集合 {
    public static int[] p = new int[100010];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        for(int i = 1; i <= n; ++ i ) {
            p[i] = i; // 刚开始每个都是自己的祖宗
        }
        while( m -- != 0) {
            String s = sc.next();
            int x, y;
            x = sc.nextInt();
            y = sc.nextInt();
            if("M".equals(s)) { // 插入的操作
                p[find(x)] = find(y);
            } else { // 查询的操作
                if(find(x) == find(y)) {
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            }
        }
    }

    public static int find(int x) {
        if(x != p[x]) {
          p[x] = find(p[x]);
        }
        return p[x];
    }
}
